package com.studay;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.studay.bean.ChannelInfo;
import com.studay.bean.Const;
import com.studay.bean.Course;
import com.studay.bean.DianBoPojo;
import com.util.EducationUtil;
import com.util.LogManager;

/**
 * 显示项目列表
 * 
 * @author LY
 * 
 */
public class ProjectActivity extends Activity {
	private ListView videoList;
	private List<Map<String, String>> video;
	private ArrayList<DianBoPojo> list;
	private ChannelInfo channelInfo ;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.index);

		View view = findViewById(R.id.titleLayout);
		view.getBackground().setAlpha(120);

		View mainLayout = findViewById(R.id.mainLayout);
		mainLayout.getBackground().setAlpha(180);

		Intent intent = this.getIntent();
		Bundle bundle = intent.getExtras();
		list = bundle.getParcelableArrayList("list");
		channelInfo = (ChannelInfo) bundle.getSerializable("channelInfo");
		String projectName = bundle.getString("projectName");
		TextView titleTextView = (TextView) findViewById(R.id.titleTextView);
		titleTextView.setText(projectName);

		TextView bottomTextView = (TextView) findViewById(R.id.bottomTextView);
		bottomTextView.setText("共计项目" + list.size() + "个");

		videoList = (ListView) findViewById(R.id.videoList);
		video = new ArrayList<Map<String, String>>();

		for (int i = 0; i < list.size(); i++) {
			DianBoPojo dbp = list.get(i);
			Map<String, String> map = new HashMap<String, String>();
			map.put("data", dbp.getName());
			map.put("url", "" + i);
			video.add(map);
		}

		SimpleAdapter mySimpleAdapter = new SimpleAdapter(this,
				video,// 数据源
				R.layout.listviewtext,// ListView内部数据展示形式的布局文件listitem.xml
				new String[] { "data", "url" },
				new int[] { R.id.listViewtext1 }// HashMap中的两个key值
		);

		videoList.setAdapter(mySimpleAdapter);

		videoList.setOnItemClickListener(new AdapterView.OnItemClickListener() {

			@SuppressWarnings("unchecked")
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				HashMap<String, String> map = (HashMap<String, String>) videoList
						.getItemAtPosition(arg2);
				LogManager.LogShow(Const.TAG, map.get("url").toString().trim(), LogManager.INFO);
				LogManager.LogShow(Const.TAG, "url:" + map.get("url") + " data:" + map.get("data"), LogManager.INFO);
				DianBoPojo dbp = list.get(EducationUtil.stringToInt(map
						.get("url").toString().trim()));
				Bundle bundle = new Bundle();
				bundle.putString("name", dbp.getName());
				bundle.putString("remark", dbp.getRemark());
				bundle.putSerializable("channelInfo", channelInfo);
				ArrayList<Course> childList = dbp.getChildList();
				bundle.putParcelableArrayList("courseList", childList);

				Intent intent = new Intent(getApplicationContext(),
						CrourseActivity.class);
				intent.putExtra("courseInfo", bundle);

				startActivity(intent);
			}
		});
	}
}